package com.atguigu.gmalllogger.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/4/16 10:09
 */
@RestController
@Slf4j
public class LoggerController {
    
    @GetMapping("/applog")
    public String logger(@RequestParam("param") String data){
        // 1. 把数据落盘. 给离线数据准备
        saveToDisk(data);
        // 2. 把数据写入到kafka中, 成为ods层数据
        sendToKafka(data);
        return "ok";
    }
    
    @Autowired
    KafkaTemplate<String, String> kafka ;
    private void sendToKafka(String data) {
        kafka.send("ods_log", data);
    }
    
    private void saveToDisk(String data) {
        log.info(data);
    }
}
